package algorithm_study.leecode;

import java.util.ArrayDeque;
import java.util.Deque;

public class ValidParentheses {
    public static void main(String[] args) {
        isValid("{[]}");
    }
    public static boolean isValid(String s) {
        Deque<Character> stack =new ArrayDeque<Character>();
        for(int i=0;i<s.length();++i){
            char temp=s.charAt(i);
            switch(temp){
                case '(': stack.push(temp);break;
                case ')': if(stack.pop()!='(')return false;
                case '[': stack.push(temp);break;
                case ']': if(stack.pop()!='[')return false;
                case '{': stack.push(temp);break;
                case '}': if(stack.pop()!='{')return false;
            }
        }
        return true;
    }
}
